<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/06/23 00:23:48 $)
// $RCSfile: client_emailarticle.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./modules/knowledgebase/functions_knowledgebase.php");
require_once ("./modules/knowledgebase/functions_clientkb.php");
require_once ("./includes/functions_users.php");
require_once ("./includes/functions_comments.php");
$template->loadLanguageSection("emailarticle");

// ======= PERMISSION CHECK =======
if ($_SWIFT["user"]["permissions"]["perm_canviewknowledgebase"] == "0" || $_SWIFT["settings"]["kb_enableclient"] == "0")
{
	$template->assign("errormessage", $_SWIFT["language"]["perminvalid"]);
	echo $template->displayTemplate("header");
	echo $template->displayTemplate("footer");
	exit;
}

if ($_POST["step"] == "1")
{
	if (trim($_POST["sendername"]) == "" || trim($_POST["fullname"]) == "" || trim($_POST["email"]) == "" || !isValidEmail($_POST["email"]))
	{
		unset($_POST["step"]);
	} else {
		emailArticle($_POST["kbarticleid"], $_POST["sendername"], $_POST["fullname"], $_POST["email"]);
		echo $template->displayTemplate("kbemailarticleconfirm");
	}
}

if (empty($_POST["step"]))
{
	$_article = getArticle($_REQUEST["kbarticleid"]);
	if (!$_article || $_article["articlestatus"] != "published")
	{
		trigger_error($_SWIFT["language"]["articleerror"], E_USER_ERROR);
	}

	$template->assign("article", $_article);

	$template->assign("sendername", $_POST["sendername"]);
	$template->assign("fullname", $_POST["fullname"]);
	$template->assign("email", $_POST["email"]);

	echo $template->displayTemplate("kbemailarticle");
}
?>